<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>功能管理页面</title>
<script type="text/javascript" src="${path}/js/scripts/bootstart.js"></script>
</head>
<body style="width: 98%; height: 90%;">
	<div id="datagrid1" class="mini-datagrid" onload="load()"
		style="width: 100%; height: 80%;" dataField="list"
		url="${path}/function/mgr/showList" pageSize="100"
		totalField="totalRecord" allowResize="false" idField="functionId"
		multiSelect="true"  showPager="false">
		<div property="columns">
			<div type="checkcolumn" renderer="render"></div>
			<div field="functionName" width="120" headerAlign="center"
				allowSort="true">功能名</div>
			<div field="code" width="120" headerAlign="center">标识</div>
			<div field="remark" width="120" headerAlign="center">描述</div>
		</div>
	</div>
	<div class="mini-toolbar"
		style="text-align: center; padding-top: 8px; padding-bottom: 8px;"
		borderStyle="border:0;">
		<a class="mini-button" style="width: 60px;" onclick="onOk()">确定</a> <span
			style="display: inline-block; width: 25px;"></span> <a
			class="mini-button" style="width: 60px;" onclick="onCancel()">取消</a>
	</div>
</body>
<script type="text/javascript" src="${path}/js/scripts/datagrid.js">
	
</script>
<script type="text/javascript">
	mini.parse();
	var doc = $(document);
	$(function() {
		$.grid.init({
			id : "datagrid1"
		});
		//清除查询条件
		griddata.Clear = function() {
			var SerachForm = new mini.Form("");
			SerachForm.reset();
		};
		//查询
		griddata.Search = function() {
			var articleSerachForm = new mini.Form("");
			var data = articleSerachForm.getData(true);
			//获取以Struts2对象封装格式的json对象 {"对象1.属性":"属性值","对象.属性2":"属性值"}
			var jsonObject = myutils.parseFormToJsonObject(data);
			$.grid.datagrid.load(jsonObject);
		};
	});
	function GetData() {
		var grid = mini.get("datagrid1");
		var gridList = grid.getList();
		var ids = [], texts = [];
		for (var i = 0; i < gridList.length; i++) {
			if (gridList[i].selected) {
				ids.push(gridList[i].functionId);
				texts.push(gridList[i].functionName);
			}
		}
		var data = {};
		data.id = ids.join(",");
		data.text = texts.join(",");
		return data;
	}

	function search() {
		var key = mini.get("key").getValue();
		grid.load({
			key : key
		});
	}
	function onKeyEnter(e) {
		search();
	}
	function CloseWindow(action) {
		if (window.CloseOwnerWindow)
			return window.CloseOwnerWindow(action);
		else
			window.close();
	}
	function onOk() {
		CloseWindow("ok");
	}
	function onCancel() {
		CloseWindow("cancel");
	}
	function render(e) {
		var idString = "${param.idString}";
		var ids = idString.split(",");
		var clickFn = 'checkFunc(\'' + e.record.functionId + '\',\''
				+ e.record.functionName + '\', this.checked)';
		var checkBox = "";
		for (var i = 0; i < ids.length; i++) {
			if (e.record.functionId.toString() == ids[i]) {
				checkBox = '<input type="checkbox" checked onclick="' + clickFn + '"/>';
				break;
			} else
				checkBox = '<input type="checkbox" onclick="' + clickFn + '"/>';
		}
		return checkBox;
	}
	/**
	 * 选择功能
	 */
	function checkFunc(fid, fname, checked) {
		var grid = mini.get("datagrid1");
		var gridList = grid.getList();
		for (var i = 0, a = gridList.length; i < a; i++) {
			if (gridList[i].functionId.toString() == fid) {
				if (checked) {
					gridList[i].selected = true;
				} else {
					gridList[i].selected = false;
				}
				break;
			}
		}
	}
	/**
	 * 数据加载完成后选中原先选中的功能
	 */
	function load() {
		var idString = "${param.idString}";
		var ids = idString.split(",");
		var grid = mini.get("datagrid1");
		var gridList = grid.getList();
		for (var i = 0, a = ids.length; i < a; i++) {
			for (var j = 0, b = gridList.length; j < b; j++) {
				if (gridList[j].functionId.toString() == ids[i]) {
					gridList[j].selected = true;
					break;
				}
			}
		}
	}
</script>
</html>